package com.rui.study.algorithm.L_亿级流量网站架构_限流详解;

import com.google.common.util.concurrent.RateLimiter;

/**
 * @program: study
 * @description:
 * @author: Yaowr
 * @create: 2019-03-06 11:00
 **/
public class SmoothBursty {

    private RateLimiter limiter = RateLimiter.create(2);

    private void process() {
        System.out.println(Thread.currentThread().getName() + " do something! [" + limiter.acquire() + "]");
    }

    public static void main(String[] args) throws InterruptedException {
        SmoothBursty smoothBursty = new SmoothBursty();
        for (int i = 0; i < 20; i++) {
            if (i == 5) {

                Thread.sleep(3000);
            }
            new Thread(()->smoothBursty.process(), "My-Worker-" + i).start();
        }
    }
}
